//商品分类全局组件的小仓库
import { defineStore } from 'pinia'
import { reqC1, reqC2, reqC3 } from '@/api/product/attr'
import type { c1Code } from '@/api/product/attr/type'
import type attrArr from './type'
const useCategoryStore = defineStore('category', {
  state: (): attrArr => {
    return {
      c1Arr: [],
      c1Id: '',
      c2Arr: [],
      c2Id: '',
      c3Arr: [],
      c3Id: '',
      getData: [],
    }
  },
  actions: {
    async getC1() {
      const res: c1Code = await reqC1()
      if (res.code == 200) {
        this.c1Arr = res.data
      }
    },
    async getC2() {
      const res: c1Code = await reqC2(this.c1Id)
      if (res.code == 200) {
        this.c2Arr = res.data
      }
    },
    async getC3() {
      const res: c1Code = await reqC3(this.c2Id)
      if (res.code == 200) {
        this.c3Arr = res.data
      }
    },
    // async getList() {
    //   const res: c1CodeAttr = await reqAttr(this.c1Id, this.c2Id, this.c3Id)
    //   console.log(res.data)
    //   if (res.code == 200) {
    //     this.getData = res.data
    //   }
    // },
  },
})
export default useCategoryStore
